using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace MyMedia.iPod.Music
{
	// Holds a reference to a particular song on the iPod
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	unsafe struct Mhip
	{
		public int TotalLength;
		public int DataObjectChildCount;
		public int PodcastGroupingFlag;
		public int GroupId;
		public int TrackId;
		public int Timestamp;
		public int PodcastGroupingReference;
		
		public void Read(BinaryReader reader)
		{
			MhHeader header = new MhHeader();
			header.Read(reader);
			Debug.Assert(header.Identifier[0] == 0x6D &&
				header.Identifier[1] == 0x68 &&
				header.Identifier[2] == 0x69 &&
				header.Identifier[3] == 0x70,
				"Mhip missmatch");
			
			byte[] data = reader.ReadBytes(header.Length - sizeof(MhHeader));
			fixed (byte* pData = data)
			{
				this = *(Mhip*)pData;
			}
		}

		public void Write(BinaryWriter writer)
		{
			//byte[] data = StructUtil.GetBytes(this);
			//writer.Write(data);

			//// Padded zeros
			//int count = HeaderLength - sizeof(Mhip);
			//for (int i = 0; i < count; i++)
			//    writer.Write((byte)0);
		}
	}
}
